package my_observer_pattern.concrete_subject;

import my_observer_pattern.observer.Observer;
import my_observer_pattern.subject.Subject;

import java.util.ArrayList;
import java.util.List;

public class SubscriptionSubject implements Subject {

    private List<Observer> wechatUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        wechatUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        wechatUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        wechatUserList.forEach(user->{
            user.update(message);
        });
    }
}
